import { generateUUID } from '@/utils'
import { localeProps, makeRequiredRule } from '@/components/FormCreate/src/utils'

export const useInputNumberGroupItemRule = () => {
  const label = '计数器'
  const name = 'InputNumberGroupItem'
  return {
    icon: 'icon-number',
    label,
    name,
    menu: 'main',
    rule() {
      return {
        type: name,
        field: generateUUID(),
        title: label,
        info: '',
        value: 0,
        $required: false,
        props: {
          modelValue: 0
        }
      }
    },
    props(_, { t }) {
      return localeProps(t, name + '.props', [
        makeRequiredRule(),
        {
          type: 'inputNumber',
          field: 'min',
          title: '设置计数器允许的最小值',
          value: undefined,
          props: { min: 0 }
        },
        {
          type: 'inputNumber',
          field: 'max',
          title: '设置计数器允许的最大值',
          value: undefined,
          props: { min: 0 }
        },
        {
          type: 'inputNumber',
          field: 'step',
          title: '计数器步长',
          value: 1,
          props: { min: 0 }
        },
        {
          type: 'switch',
          field: 'stepStrictly',
          title: '是否只能输入 step 的倍数',
          value: false
        },
        {
          type: 'inputNumber',
          field: 'precision',
          title: '数值精度',
          value: undefined,
          props: { min: 0 }
        },
        {
          type: 'select',
          field: 'size',
          title: '计数器尺寸',
          value: 'default',
          options: [
            { label: '默认', value: 'default' },
            { label: '大', value: 'large' },
            { label: '小', value: 'small' }
          ]
        },
        {
          type: 'switch',
          field: 'disabled',
          title: '是否禁用计数器',
          value: false
        },
        {
          type: 'switch',
          field: 'controls',
          title: '是否使用控制按钮',
          value: true
        },
        {
          type: 'select',
          field: 'controlsPosition',
          title: '控制按钮位置',
          value: '',
          options: [
            { label: '默认', value: '' },
            { label: '右侧', value: 'right' }
          ]
        },
        {
          type: 'input',
          field: 'placeholder',
          title: '占位文本',
          value: ''
        }
      ])
    }
  }
}